package solitaire.presentation;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import solitaire.InterfacesControle.ICSabot;
import solitaire.InterfacesPresentation.IPCarte;
import solitaire.InterfacesPresentation.IPSabot;
import solitaire.InterfacesPresentation.IPTas;
import solitaire.controle.CSabot;


public class PSabot extends JPanel implements IPSabot{

	private ICSabot controleur;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Box main;
	private IPTas visible;
	private IPTas cache;
	
	public static int largeur ;
	public static int hauteur ;

	public PSabot(IPTas visibles,IPTas caches){
		
		this.visible=visibles;
		this.cache=caches;
		
		//donner un layout plus "serré" pour les cartes du tas caché
		caches.setLayout(new OverlapLayout(new Point(0,0)));
		
		MouseListener listener = new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
			}
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
			}
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				controleur.clicSabot();
			}
		};
		main = Box.createHorizontalBox();

		JButton button=new JButton("+ 3 Cartes");
        button.addMouseListener(listener);			
		main.add(button);
		main.add(cache.getJComponent());
		main.add(visible.getJComponent());
		add(main);
	}
	
	public static void initDimensions () {
		ImageIcon icone = new ImageIcon (ClassLoader.getSystemResource("cartesCSHD/1C.gif")) ;
		largeur = icone.getIconWidth () ;
		hauteur = icone.getIconHeight () ;
	}
	
	@Override
	public void empiler(IPCarte carte) {
		visible.getJComponent().add(carte.getJPanel());
		main.repaint();
	}


	@Override
	public JComponent getJComponent() {
		return this;
	}

	@Override
	public void setControleur(CSabot cSabot) {
		controleur = cSabot;
		
	}


	public static void main (String args []) {
		JFrame f = new JFrame ("Test PCarte") ;
		f.addWindowListener (new WindowAdapter () {
			public void windowClosing (WindowEvent e) {
				System.exit (0) ;
			}
		}) ;

	}

	@Override
	public void depiler() {
		// TODO Auto-generated method stub
		
	}

}
